FROM ghcr.nju.edu.cn/1panel-dev/maxkb-python-pg:python3.11-pg15.8
COPY ./app /opt/wlou/app
COPY ./init.sql /opt/wlou/init.sql
COPY ./start.sh /opt/wlou/start.sh
WORKDIR /opt/wlou/app
# 更换源为阿里云源
RUN cp -f /opt/wlou/init.sql /docker-entrypoint-initdb.d && \
    sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    sed -i 's/apt.postgresql.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    chmod 777 /tmp && \
    apt update && \
    apt install -y --no-install-recommends libgl1 libglx-mesa0 libglib2.0-0 libglib2.0-dev && \
    apt clean all  && \
    rm -rf /var/lib/apt/lists/*  && \
    mkdir -p /opt/wlou/model && \
    mkdir -p /opt/wlou/sandbox/python-packages && \
    chmod 755 /opt/wlou/start.sh && \
    curl -L --connect-timeout 120 -m 1800 https://resource.fit2cloud.com/maxkb/ffmpeg/get-ffmpeg-linux | sh && \
    useradd --no-create-home --home /opt/wlou/sandbox sandbox -g root && \
    chown -R sandbox:root /opt/wlou/sandbox && \
    chmod g-x /usr/local/bin/* /usr/bin/* /bin/* /usr/sbin/* /sbin/* /usr/lib/postgresql/15/bin/* && \
    chmod g+x /usr/local/bin/python* /bin/sh && \
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
    pip install poetry==1.8.5 --break-system-packages && \
    poetry config virtualenvs.create false && \
    if [ "$(uname -m)" = "x86_64" ]; then sed -i 's/^torch.*/torch = {version = "^2.2.1+cpu", source = "pytorch"}/g' pyproject.toml; fi && \
    poetry source add tsinghua https://pypi.tuna.tsinghua.edu.cn/simple
    # poetry install --no-root

ENV WLOU_VERSION="v1.0.0 (build at wlou, commit: 1.0.0)" \
    WLOU_CONFIG_TYPE=ENV \
    WLOU_DB_NAME=wloudb \
    WLOU_DB_HOST=127.0.0.1 \
    WLOU_DB_PORT=5432  \
    WLOU_DB_USER=wloucn \
    WLOU_DB_PASSWORD=NXR2nNXJwm4w5STd \
    WLOU_DB_MAX_OVERFLOW=80 \
    WLOU_EMBEDDING_MODEL_NAME=shibing624/text2vec-base-chinese \
    WLOU_EMBEDDING_MODEL_PATH=/opt/wlou/model/embedding \
    WLOU_SANDBOX=1 \
    LANG=en_US.UTF-8 \
    POSTGRES_USER=root \
    POSTGRES_PASSWORD=Jwm4w5STdNXR2nNX \
    POSTGRES_MAX_CONNECTIONS=1000 \
    PIP_TARGET=/opt/wlou/sandbox/python-packages \
    PYTHONPATH=/opt/wlou/sandbox/python-packages \
    PYTHONUNBUFFERED=1 \
    HF_ENDPOINT=https://hf-mirror.com


# RUN curl https://pyenv.run | bash
# RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
# RUN echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
# RUN echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc
# RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# RUN . ~/.bashrc
# RUN nvm install 18

EXPOSE 9090
EXPOSE 5432

# ENTRYPOINT ["bash", "-c"]
# CMD ["/opt/wlou/start.sh"]